// 创建一个路由器，并暴露出去

// 第一步：引入createRouter
import {createRouter,createWebHistory,createWebHashHistory} from 'vue-router'
// 引入一个一个可能要呈现组件
import Home from '@/components/Home.vue'
import News from '/src/components/News.vue'
import About from '@/components/About.vue'
import Dog from '@/components/Dog.vue'
import Login from '@/page/Login.vue'
import Index from '@/page/index.vue'
import Admin from '@/layouts/admin.vue'
import Detail from '@/page/Detail.vue'
import SysUser from '@/view/sys/user/index.vue'
import NotFound from '@/page/404.vue'

// 第二步：创建路由器
const router= createRouter({
  history:createWebHashHistory(), //路由器的工作模式（稍后讲解）
  routes:[ 
    {
      path:"/",
      component: () => import('@/layouts/admin.vue'),
      redirect: "/index",
      // 子路由
      children:[{
          path:"/",
          component:Index,
          meta:{
              title:"后台首页"
          },
          children:[{
            path:"/about",
            component:About,
            meta:{
                title:"关于"
            }
          },{
            path:"/news",
            name: "xinwen",
            component:News,
            meta:{
                title:"新闻"
            },
            children:[{
              path:"detail",
              name:"xiang",
              component: Detail,
              meta:{
                  title:"新闻详情"
              },
              props(router){
                return router.query
              }
            }]
          },{
            path:"/home",
            component:Home,
            meta:{
                title:"主页"
            }
          },{
            path:"/dog",
            component:Dog,
            meta:{
                title:"宠物"
            }
          }]
      },
      {
        path:"/sys/user",
        component: () => import("/src/view/sys/user/index.vue"),
        
      },
      {
        path:"/sys/role",
        component: () => import("/src/view/sys/role/index.vue"),
        
      },
      {
        path:"/sys/menu",
        component: () => import("/src/view/sys/menu/index.vue"),
        
      },
      {
        path:"/bsns/department",
        component: () => import("/src/view/bsns/department.vue"),
        
      },
      {
        path:"/bsns/post",
        component: () => import("/src/view/bsns/post.vue"),
        
      }
    ]
  },
  {
     path:"/login",
     component: Login,
     meta:{
       title:"登录页"
     }
   },
   {
    path: '/:pathMatch(.*)',
    //访问主页的时候 重定向到index页面
    redirect: '/404',
  },
  {
    path: '/404',
    name: '/404',
    component: NotFound
  }
  ]
})

// 暴露出去router
export default router
